from FlaskOAPro import make_app
from flask_script import Command,Manager
from flask_migrate import Migrate,MigrateCommand

from FlaskOAPro.OAPro.models import db


# class MiddleWare(object):
#     def __init__(self,old_app):
#         self.old_app = old_app
#     def __call__(self, environ,start_response):
#         print("中间件开始")
#         ret = self.old_app(environ,start_response)
#         print("执行结束")
#         return ret

app = make_app() #得到flask app对象

migrate = Migrate(app,db) #绑定应用和数据库

class SayHello(Command):
    def run(self):
        print("hello world")

class OurRun(Command):
    def run(self):
        # app.wsgi_app = MiddleWare(app.wsgi_app)
        app.run(host = "0.0.0.0",debug = True,use_reloader = True)



manage = Manager(app) #命令行绑定应用
manage.add_command("say_hello",SayHello) #安装命令
manage.add_command("run",OurRun) #安装命令
manage.add_command("db",MigrateCommand) #安装命令


if __name__ == '__main__':
    manage.run() #启动命令行